package com.project.easy.common.framework.web.service.impl;

import com.project.easy.common.log.core.dto.WriteLogDto;
import com.project.easy.common.log.core.service.ILogPersistent;
import com.project.easy.common.framework.web.entity.FrameworkOperationLog;
import com.project.easy.common.framework.web.service.IFrameworkOperationLogService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author GreatorMan.cool
 * @copyright: Copyright (c) 2020
 * @company: 扬起科技有限公司
 * @date 2021/10/26 22:10
 * @description:持久化
 */
@Component
public class DefaultMysqlLogPersistent implements ILogPersistent {

    @Autowired(required = false)
    private IFrameworkOperationLogService frameworkOperationLogService;
    /**
     * 持久化日志
     *
     * @param writeLogDto 日志对象
     * @return true 保存成功 false 保存失败
     */
    @Override
    public Boolean save(WriteLogDto writeLogDto) {
        if (!Objects.isNull(frameworkOperationLogService)) {
            FrameworkOperationLog frameworkOperationLog = new FrameworkOperationLog();
            BeanUtils.copyProperties(writeLogDto, frameworkOperationLog);
            frameworkOperationLog.setLogStatus(writeLogDto.getLogStatus());
            frameworkOperationLog.setInput("{}");
            frameworkOperationLog.setContent("");
            this.frameworkOperationLogService.save(frameworkOperationLog);
        }
        return Boolean.TRUE;
    }
}
